<div class="doc-item" id="doc-743"><h2 class="doc-item-name">defmonadfn<span class="namespace">(clojure.contrib.monads)</span></h2><p class="macro">Macro</p><ul class="var-arglists"><li>(<span class="var-name">defmonadfn</span> name docstring? attr-map? args expr)</li><li>(<span class="var-name">defmonadfn</span> name docstring? attr-map? (args expr) ...)</li></ul><div class="var-docstring"><p>Like defn, but for functions that use monad operations and are used inside
   a with-monad block.</p></div><div class="var-source"><pre>; clojure/contrib/monads.clj:137
(defmacro defmonadfn
  {:arglists '([name docstring? attr-map? args expr]
	       [name docstring? attr-map? (args expr) ...])}
  [name &amp; options]
  (let [[name options]  (name-with-attributes name options)
	fn-name (symbol (str *ns*) (format &quot;m+%s+m&quot; (str name)))
	make-fn-body    (fn [args expr]
			  (list (vec (concat ['m-bind 'm-result
					      'm-zero 'm-plus] args))
				(list `with-symbol-macros expr)))]
    (if (list? (first options))
      ; multiple arities
      (let [arglists        (map first options)
	    exprs           (map second options)
	    ]
	`(do
	   (defsymbolmacro ~name (partial ~fn-name ~'m-bind ~'m-result 
                                                   ~'m-zero ~'m-plus))
	   (defn ~fn-name ~@(map make-fn-body arglists exprs))))
      ; single arity
      (let [[args expr] options]
	`(do
	   (defsymbolmacro ~name (partial ~fn-name ~'m-bind ~'m-result 
                                                   ~'m-zero ~'m-plus))
	   (defn ~fn-name ~@(make-fn-body args expr)))))))</pre></div><div class="license"><p>Copyright (c) Rich Hickey. All rights reserved.</p><p>The use and distribution terms for this software are covered by the <a href="http://opensource.org/licenses/eclipse-1.0.php">Eclipse Public License 1.0</a>, which can be found in the file
          epl-v10.html at the root of this distribution. By using this software
          in any fashion, you are agreeing to be bound by the terms of this
          license. You must not remove this notice, or any other, from this
          software.</p></div></div>